class Solution:
    def integerReplacement(self, n: int) -> int:
        time = 0
        while n!=1:
            print("{0:b}".format(n))
            time += 1
            if n&1==0:
                n=n>>1
            else:
                if n&7==7 or n&11==11:
                    n = n + 1
                else:
                    n = n-1
        return time

if __name__ == '__main__':
    so = Solution()
    n=1234
    r = so.integerReplacement(n)
    print(r)
    print(int('1011',2))

